package com.jb.security.event;

import com.jb.web.bean.event.UIEvent;
import com.jb.web.context.WebContext;
import com.jb.web.form.BeanForm;
import  com.jb.security.SecurityManager;
import com.jb.web.session.SessionUser;

public class UserAccountEH {
    public void onCreate(WebContext ctx, UIEvent event) {
        BeanForm bean =(BeanForm) event.getSource();
        SecurityManager sm = ctx.getSession().getSecurityManager();
        String userName = event.getParameter("userName");
        String password = event.getParameter("password");
        try
        {
            SessionUser user = sm.createUser(ctx, userName, password);
            user.setScreenName(event.getParameter("screenName"));
            sm.updateUser(ctx, user);
            bean.resetForm();
        }catch(Exception e) {
            ctx.addErrorMessage(this, "Failed to create user "+userName);
        }
    }
}
